package com.ks.controller;

import com.ks.common.PageResult;
import com.ks.vo.ReceiveVO;
import com.ks.common.Result;
import com.ks.dto.MetricDataDTO;
import com.ks.dto.PageQueryDTO;
import com.ks.service.MetricDataService;
import com.ks.vo.MetricDataVO;
import com.ks.vo.RequestVO;
import com.ks.vo.ResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/metric")
@Slf4j
public class MetricDataController {

    @Autowired
    private MetricDataService metricDataService;

    @PostMapping("/put")
    public ReceiveVO dealMonitorData(@RequestBody List<MetricDataDTO> metricDataDTOList) {
        return metricDataService.dealMonitorData(metricDataDTOList);
    }

    //分页查询数据列表
    @PostMapping("/list")
    public Result<PageResult> list(@RequestBody PageQueryDTO pageQueryDTO) {
        PageResult pageResult = metricDataService.pageMetricData(pageQueryDTO);
        return Result.success(pageResult);
    }


    //分页查询图表数据
    @PostMapping("/chart/{metric}")
    public Result<PageResult> chart(@RequestBody PageQueryDTO pageQueryDTO, @PathVariable String metric) {
        PageResult pageResult = metricDataService.pageChartData(pageQueryDTO, metric);
        return Result.success(pageResult);
    }

    // 根据时间范围查询监控数据
    @PostMapping("/query")
    public ResponseVO queryMetricDataByTime(@RequestBody RequestVO requestVO) {
        List<MetricDataVO> metricDataList = metricDataService.queryMetricDataByTime(requestVO);
        return ResponseVO.success(metricDataList,requestVO,metricDataList.size());
    }


}
